package com.greedy.controller;

import com.greedy.bean.pojo.Voucher;
import com.greedy.service.VoucherService;
import com.greedy.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Yanxy
 * @Date: Created in:2022-12-24
 * Description: 商铺优惠券信息
 */
@RestController
@RequestMapping("/voucher")
public class VoucherController {

    @Resource
    private VoucherService voucherService;

    /**
     * 新增秒杀券
     * (此应为后台操作，只写了客户端所以，添加秒杀优惠卷的过程是靠本地演示)
     * @param voucher 优惠券信息，包含秒杀信息
     * @return 优惠券id
     */
    @PostMapping("/seckill")
    public Result addSeckillVoucher(@RequestBody Voucher voucher) {
        Long id = voucherService.addSeckillVoucher(voucher);
        return Result.ok(id);
    }

    /**
     * 新增普通券
     * @param voucher 优惠券信息
     * @return 优惠券id
     */
    @PostMapping
    public Result addVoucher(@RequestBody Voucher voucher) {
        Long id = voucherService.save(voucher);
        return Result.ok(id);
    }


    /**
     * 查询店铺的优惠券列表
     * @param shopId 店铺id
     * @return 优惠券列表
     */
    @GetMapping("/list/{shopId}")
    public Result queryVoucherOfShop(@PathVariable("shopId") Long shopId) {
        List<Voucher> vouchers = voucherService.queryVoucherOfShop(shopId);
        return Result.ok(vouchers);
    }
}
